package 第五章继承.object.equals方法;

import 第四章类与对象.员工类.Employee;

import java.time.LocalDate;

//创建一个staff1类用来体会equals方法
public class Staff1 extends Employee {

    //加入一个特有的字段age；
    private int age;

    public Staff1() {
    }

    public Staff1(String name, double salary, LocalDate hireDay, int age) {
        super(name, salary, hireDay);
        this.age = age;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    //重写原方法的get和set方法
    @Override
    public String getName() {
        return super.getName();
    }

    @Override
    public void setName(String name) {
        super.setName(name);
    }

    @Override
    public double getSalary() {
        return super.getSalary();
    }

    @Override
    public void setSalary(double salary) {
        super.setSalary(salary);
    }

    @Override
    public LocalDate getHireDay() {
        return super.getHireDay();
    }

    @Override
    public void setHireDay(LocalDate hireDay) {
        super.setHireDay(hireDay);
    }

    //重写父类的equals方法
    @Override
    public boolean equals(Object obj) {
        //父类的equasls方法如果显示false，则直接返回false；
        if (!super.equals(obj)) {
            return false;
        }

        //因为在父类中已经知道两个引用的类型相同，所以可以直接把传入的引用类型强转为Staff1类；
        Staff1 staff1 = (Staff1) obj;
        return this.age == staff1.age;
    }
}
